var t = require("../../../@babel/runtime/helpers/interopRequireDefault"), a = require("../../../@babel/runtime/helpers/defineProperty"), e = t(require("../../../@babel/runtime/regenerator")), s = require("../../../@babel/runtime/helpers/asyncToGenerator"), i = getApp(), o = require("../../../mybehaviors/location/location");

Page({
    behaviors: [ o ],
    data: {
        customer_open: !0,
        swlis: [],
        uploadUrl: "",
        o2o_status: 1,
        address: "",
        point: {
            lat: "",
            lng: ""
        },
        city: "",
        title: "",
        noIs: !0,
        bor: !0,
        showDel: !1,
        applyModel: {
            name: "",
            mobile: "",
            id_card_number: "",
            user_comment: "",
            lng: "",
            lat: "",
            id_card_image_front: "",
            id_card_image_back: "",
            other_image: [],
            provinceId: "",
            cityId: "",
            districtId: "",
            streetId: "",
            address: ""
        },
        strShow: !1,
        provinceData: [],
        cityData: [],
        districtData: [],
        pickerValue: [ 0, 0, 0 ],
        selectAddressData: [],
        districtVal: [],
        streetShow: !1,
        addressShow: !1,
        addressName: "",
        provice: "",
        imageUrl: "",
        goods_id: "",
        status: !1,
        explainFlag: !1,
        slideList: [],
        apply_id: 0
    },
    onLoad: function(t) {
        var a = this;
        try {
            wx.removeStorageSync("applyaddresspoint");
        } catch (t) {}
        this.setData({
            uploadUrl: "upload.uploadPic"
        }), this._initAddressInfo(), this.getData(), this._getLocation(function(t, e) {
            a.setData({
                "applyModel.lng": e.lng,
                "applyModel.lat": e.lat,
                mapdata_address: t.address
            });
        });
    },
    cancelApply: function() {
        var t = this;
        return s(e.default.mark(function a() {
            var s, o;
            return e.default.wrap(function(a) {
                for (;;) switch (a.prev = a.next) {
                  case 0:
                    return a.next = 2, i.confirm("确定取消审核吗?");

                  case 2:
                    if (0 != a.sent) {
                        a.next = 5;
                        break;
                    }
                    return a.abrupt("return");

                  case 5:
                    s = t.data.apply_id, o = i.getNetAddresss("plugin.live-install.frontend.worker-apply.cancelApply"), 
                    i._getNetWork({
                        url: o,
                        data: {
                            apply_id: s
                        },
                        success: function(a) {
                            var e = a.data;
                            i.tips(e.msg), 1 == e.result && t.goHome();
                        }
                    });

                  case 8:
                  case "end":
                    return a.stop();
                }
            }, a);
        }))();
    },
    setExplainFlag: function() {
        this.setData({
            explainFlag: !this.data.explainFlag
        });
    },
    showdel: function(t) {
        console.log(t), this.setData({
            showDel: !0
        });
    },
    delIntu_2: function(t) {
        var a = this.data.showpaths_two, e = t.currentTarget.id;
        a.splice(e, 1), this.setData({
            showpaths_two: a,
            "applyModel.other_image": a
        });
    },
    onReady: function() {},
    onShow: function() {
        try {
            var t = wx.getStorageSync("applyaddresspoint");
            t && (this.setData({
                "applyModel.lng": t.point.lng,
                "applyModel.lat": t.point.lat,
                mapdata_address: t.address
            }), console.log(this.data.applyModel));
        } catch (t) {
            console.log(t);
        }
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    toGeolocation: function() {
        wx.navigateTo({
            url: "/packageC/o2o/o2oLocation_loc/o2oLocation_loc?tag=storeApply"
        });
    },
    tapUrl: function(t) {
        var a = t.currentTarget.dataset.url;
        if ("" == a) return !1;
        wx.navigateTo({
            url: a
        });
    },
    getData: function() {
        var t = this, a = i.getNetAddresss("plugin.live-install.frontend.worker-apply.getWorkerApply");
        i._getNetWork({
            url: a,
            success: function(a) {
                var e = a.data;
                if (1 != e.result) return i.tips(e.msg);
                var s = e.data.apply_text.replace(/<img/g, '<img style="max-width:100%"');
                t.setData({
                    slideList: e.data.slide_list,
                    o2o_status: e.data.apply_data.apply_id > 0 ? 2 : 1,
                    apply_id: e.data.apply_data.apply_id,
                    apply_text: s
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    nameinp: function(t) {
        var a = t.detail.value;
        this.setData({
            "applyModel.name": a
        });
    },
    mobileinp: function(t) {
        var a = t.detail.value;
        this.setData({
            "applyModel.mobile": a
        });
    },
    idcardnumberinp: function(t) {
        var a = t.detail.value;
        this.setData({
            "applyModel.id_card_number": a
        });
    },
    addressShowbtn: function() {
        this.setData({
            addressShow: !0
        });
    },
    showAddBtn: function(t) {
        var e = t.currentTarget.dataset.idex;
        this.setData(a({}, "diydata[" + e + "].showAdd", !0));
    },
    _closeDateLw: function() {
        this.setData({
            addressShow: !1
        });
    },
    _initAddressInfo: function() {
        var t = this;
        wx.getStorage({
            key: "provinceData",
            success: function(a) {
                console.log("地址信息准备就绪"), t._getProvinceData();
            },
            fail: function(a) {
                console.log("省fail"), i._getNetWork({
                    url: i.getNetAddresss("member.member-address.address"),
                    success: function(a) {
                        var e = a.data, s = e.data.province, i = e.data.city, o = e.data.district;
                        wx.setStorage({
                            key: "provinceData",
                            data: s
                        }), wx.setStorage({
                            key: "cityData",
                            data: i
                        }), wx.setStorage({
                            key: "districtData",
                            data: o
                        }), t._initAddressInfo();
                    },
                    fail: function(t) {},
                    state: !0
                });
            }
        });
    },
    _getProvinceData: function() {
        var t = this;
        wx.getStorage({
            key: "provinceData",
            success: function(a) {
                console.log("省读取成功", a.data), t.setData({
                    provinceData: a.data
                }), t.setData({
                    "selectAddressData[0].name": a.data[t.data.pickerValue[0]].areaname,
                    "selectAddressData[0].id": a.data[t.data.pickerValue[0]].id,
                    "selectAddressData[0].index": t.data.pickerValue[0]
                }), t._getCityData();
            }
        });
    },
    _getCityData: function() {
        var t = this.data.selectAddressData[0];
        console.log("城市", "_data", t);
        var a = this;
        wx.getStorage({
            key: "cityData",
            success: function(e) {
                console.log("城市读取成功", e);
                for (var s = [], i = 0; i < e.data.length; i++) e.data[i].parentid == t.id && s.push(e.data[i]);
                console.log("城市数据筛选", s), a.setData({
                    cityData: s
                }), a.setData({
                    "selectAddressData[1].name": s[a.data.pickerValue[1]].areaname,
                    "selectAddressData[1].id": s[a.data.pickerValue[1]].id,
                    "selectAddressData[1].index": a.data.pickerValue[1]
                }), a._getDistrictData();
            }
        });
    },
    _getDistrictData: function() {
        var t = this.data.selectAddressData[1];
        console.log("地区", "_data", t), console.log(t);
        var a = this;
        wx.getStorage({
            key: "districtData",
            success: function(e) {
                console.log("地区读取成功");
                for (var s = [], i = 0; i < e.data.length; i++) e.data[i].parentid == t.id && s.push(e.data[i]);
                console.log("地区数据筛选", s), a.setData({
                    districtData: s
                }), console.log("districtData", s), a.setData({
                    "selectAddressData[2].name": s[a.data.pickerValue[2]].areaname,
                    "selectAddressData[2].id": s[a.data.pickerValue[2]].id,
                    "selectAddressData[2].index": a.data.pickerValue[2]
                }), console.log("over", a.data.selectAddressData);
            }
        });
    },
    bindChange: function(t) {
        var a = t.detail.value;
        this.data.pickerValue[0] != a[0] && (a[1] = 0, a[2] = 0), this.data.pickerValue[1] != a[1] && (a[2] = 0), 
        this.setData({
            "pickerValue[0]": a[0],
            "pickerValue[1]": a[1],
            "pickerValue[2]": a[2]
        }), this._initAddressInfo();
    },
    resultAdd: function() {
        var t = this.data.selectAddressData, a = t[0].name + " " + t[1].name + " " + t[2].name;
        this.setData({
            addressName: a,
            provice: t[0].name,
            city: t[1].name,
            district: t[2].name
        }), this.setData({
            "applyModel.provinceId": t[0].id,
            "applyModel.cityId": t[1].id,
            "applyModel.districtId": t[2].id,
            addressShow: !1
        }), this.getStreet(t[2].id);
    },
    getStreet: function(t) {
        var a = this, e = "";
        e += i.getNetAddresss("member.memberAddress.street"), e += "&district_id=" + t, 
        i._getNetWork({
            url: e,
            success: function(t) {
                var e = t.data;
                1 == e.result && !i._isTextEmpty(e.data) && e.data.length > 0 ? a.setData({
                    districtVal: e.data,
                    strShow: !0
                }) : a.setData({
                    strShow: !1
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    streetShowbtn: function() {
        this.setData({
            streetShow: !0
        });
    },
    treetShowLeft: function() {
        this.setData({
            streetShow: !1
        });
    },
    streetConfirm: function(t) {
        var a = t.currentTarget.dataset.item;
        this.setData({
            street: a.areaname,
            "applyModel.streetId": a.id,
            streetShow: !1
        });
    },
    addressinp: function(t) {
        var a = t.detail.value;
        this.setData({
            "applyModel.address": a
        });
    },
    onRead_6: function() {
        var t = this;
        wx.chooseImage({
            count: 9,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(a) {
                t.unload({
                    tempFilePaths: a.tempFilePaths
                });
            }
        });
    },
    unload: function(t) {
        var a = i.getNetAddresss(this.data.uploadUrl), e = this, s = t.i ? t.i : 0, o = t.success ? t.success : 0, r = t.fail ? t.fail : 0;
        wx.uploadFile({
            url: a,
            filePath: t.tempFilePaths[s],
            name: "file",
            formData: null,
            success: function(t) {
                var a = JSON.parse(t.data);
                console.log(a.data.img_url), e.data.swlis.push(a.data.img_url), e.setData({
                    showpaths_two: e.data.swlis,
                    "applyModel.other_image": e.data.swlis
                }), console.log(e.data.applyModel);
            },
            fail: function(t) {
                r++;
            },
            complete: function(a) {
                ++s == t.tempFilePaths.length ? (console.log("执行完毕"), console.log("成功：" + o + " 失败：" + r)) : (t.i = s, 
                t.success = o, t.fail = r, e.unload(t));
            }
        });
    },
    onRead_4: function() {
        var t = this, a = i.getNetAddresss(this.data.uploadUrl);
        wx.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(e) {
                var s = e.tempFilePaths;
                console.log(s[0]);
                var i = s[0];
                wx.uploadFile({
                    url: a,
                    filePath: i,
                    name: "file",
                    success: function(a) {
                        var e = JSON.parse(a.data);
                        1 == e.result ? (t.setData({
                            fileList4: i,
                            "applyModel.id_card_image_front": e.data.img_url
                        }), console.log(t.data.applyModel.idCardImg)) : wx.showToast({
                            icon: "none",
                            title: e.msg,
                            duration: 1500
                        });
                    }
                });
            }
        });
    },
    onRead_5: function() {
        var t = this, a = i.getNetAddresss(this.data.uploadUrl);
        wx.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(e) {
                var s = e.tempFilePaths;
                console.log(s[0]);
                var i = s[0];
                wx.uploadFile({
                    url: a,
                    filePath: i,
                    name: "file",
                    success: function(a) {
                        var e = JSON.parse(a.data);
                        1 == e.result ? (t.setData({
                            fileList5: e.data.img_url,
                            "applyModel.id_card_image_back": e.data.img_url
                        }), console.log(t.data.applyModel)) : wx.showToast({
                            icon: "none",
                            title: e.msg,
                            duration: 1500
                        });
                    }
                });
            }
        });
    },
    remarkinp: function(t) {
        var a = t.detail.value;
        console.log(a), this.setData({
            "applyModel.user_comment": a
        });
    },
    Chooseinp: function(t) {
        var a = t.detail;
        this.setData({
            agreementChoose: a
        });
    },
    setApplyData: function() {
        var t = this;
        if (console.log(this.data.applyModel), i._isTextEmpty(this.data.applyModel.name)) return i.tips("请填写姓名");
        if (i._isTextEmpty(this.data.applyModel.mobile)) return i.tips("请填写手机号");
        if (i._isMoblie(this.data.applyModel.mobile)) return i.tips("请输入正确的手机号");
        if (i._isTextEmpty(this.data.applyModel.id_card_number)) return i.tips("请填写身份证号");
        if (i._isTextEmpty(this.data.applyModel.provinceId) || i._isTextEmpty(this.data.applyModel.cityId) || i._isTextEmpty(this.data.applyModel.districtId)) return i.tips("请选择省市区");
        if (i._isTextEmpty(this.data.applyModel.streetId)) return i.tips("请选择街道");
        if (i._isTextEmpty(this.data.applyModel.address)) return i.tips("请填写详细地址");
        if (i._isTextEmpty(this.data.applyModel.lng) || i._isTextEmpty(this.data.applyModel.lat)) return i.tips("经纬度不能为空");
        if (i._isTextEmpty(this.data.applyModel.id_card_image_front)) return i.tips("请上传身份证正面");
        if (i._isTextEmpty(this.data.applyModel.id_card_image_back)) return i.tips("请上传身份证反面");
        if (!this.data.agreementChoose) return i.tips("请同意申请协议");
        var a = JSON.parse(JSON.stringify(this.data.applyModel));
        a.longitude = a.lng, a.latitude = a.lat;
        var e = i.getNetAddresss("plugin.live-install.frontend.worker-apply.addApply");
        i._postNetWork({
            url: e,
            data: a,
            success: function(a) {
                var e = a.data;
                i.tips(e.msg), 1 == e.result && setTimeout(function() {
                    t.goHome();
                }, 1500);
            },
            fail: function(t) {}
        });
    },
    goOrder: function() {
        var t = this.data.goods_id;
        wx.redirectTo({
            url: "/packageD/buy/myOrder_v2/myOrder_v2?tag=-2&goodsId=" + t + "&optionsId=&total=1"
        });
    },
    goHome: function() {
        wx.reLaunch({
            url: "/packageG/index/index"
        });
    },
    watch: {
        "shenqShow,categoryShow,addressShow,streetShow,levelShow,show1": function(t, a) {
            var e = this;
            console.log("刷新改变"), setTimeout(function() {
                e.setData({
                    coverViewFlag: t
                });
            }, 1e3);
        }
    },
    setWatcher: function(t, a) {
        var e = this;
        Object.keys(a).forEach(function(s) {
            for (var i = s.split(","), o = 0; o < i.length; o++) e.observe(t, i[o], a[s]);
        });
    },
    observe: function(t, a, e) {
        var s = this, i = t[a];
        Object.defineProperty(t, a, {
            configurable: !0,
            enumerable: !0,
            set: function(t) {
                i = t, e.call(s, t, i);
            },
            get: function() {
                return i;
            }
        });
    }
});